<?php
require_once('mysql.php');

$task_id = $_GET['task_id'];

$json = array();

// GET THE NAME AND DESCRIPTION
$query = "SELECT * from todo_entry where id = $task_id";
$result = mysql_query($query) or die('1'.mysql_error());
$row = mysql_fetch_assoc($result);
$owner_id = $row['owner_id'];
$json['list_id'] = $row['list_id'];
$json['text'] = $row['text'];
$json['id'] = $task_id;

$query = "SELECT displayname from users where id = $owner_id";
$result = mysql_query($query) or die('u'.mysql_error());
$row = mysql_fetch_assoc($result);
$json['displayname'] = $row['displayname'];

$query = "SELECT comment.owner_id, comment.text FROM entry_comment AS comment WHERE comment.entry_id=$task_id ORDER BY comment.modify_date";
$result = mysql_query($query) or die('2'.mysql_error());

$comments = array();
while($row = mysql_fetch_assoc($result)) {
	$comment = array();
	$comment['text'] = $row['text'];
	$owner_id = $row['owner_id'];

	$query = "SELECT displayname from users where id = $owner_id";
	$name_result = mysql_query($query) or die('u'.mysql_error());
	$name_row = mysql_fetch_assoc($name_result);
	$comment['displayname'] = $name_row['displayname'];

	$comments[] = $comment;
}
$json['comments'] = $comments;
echo json_encode($json);

?>

